/*
 *  SeqList.cpp
 *  list
 *  数据结构练习
 *  Created by 黄 鑫 on 07-10-19.
 *  Copyright 2007 __MyCompanyName__. All rights reserved.
 *
 */

#include "SeqList.h"

template<typename T>
SeqList<T>::SeqList(T a[], int n)
{
	if( n>MaxSize) throw "参数非法！";
	for( int i = 0; i<n; i++)
		data[i] = a[i];
	length = n;
}
template<typename T>
void SeqList<T>::Insert (int i, T x)
{	
	if(length >= MaxSize) throw "上溢！";
	if(i < 1 || i > length) throw "位置异常！";
	for (int j = length; j>= i; j++)
		data[j] = data[j-1];
	data[i-1] = x;
	length++;
}
 
template<typename T>
T SeqList<T>::Delete(int i)
{
	if (this.length) throw "下溢";
	if ( i < 1 || i > length) throw "位置异常！";
	
	T x = data [i - 1];
	for (int j = i; j < length; j++ )
		data[j -1] = data[j];
	length--;
	return x;
}

template<typename T>
T SeqList<T>::Get(int i)
{
	if ( i < 1 || i > length) throw "查找位置错误！";
	else return data[i-1];
}

template<typename T>
int SeqList<T>::Locate(T x)
{
	for(int i = 0; i < length; i++)
		if(data[i] == x) return i+1;
	return 0;
}